1 Imports System.Data.SqlClient
2 Public Class frmChangePassword
3 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
4 Try
5 Dim RowsAffected As Integer = 0
6 If Len(Trim(UserID.Text)) = 0 Then
7 MessageBox.Show("Please enter user id", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
8 UserID.Focus()
9 Exit Sub
10 End If
11 If Len(Trim(OldPassword.Text)) = 0 Then
12 MessageBox.Show("Please enter old password", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
13 OldPassword.Focus()
14 Exit Sub
15 End If
16 If Len(Trim(NewPassword.Text)) = 0 Then
17 MessageBox.Show("Please enter new password", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
18 NewPassword.Focus()
19 Exit Sub
20 End If
21 If Len(Trim(ConfirmPassword.Text)) = 0 Then
22 MessageBox.Show("Please confirm new password", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
23 ConfirmPassword.Focus()
24 Exit Sub
25 End If
26 If NewPassword.TextLength < 5 Then
27 MessageBox.Show("The New Password Should be of Atleast 5 Characters", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
28 NewPassword.Text = ""
29 ConfirmPassword.Text = ""
30 NewPassword.Focus()
31 Exit Sub
32 ElseIf NewPassword.Text <> ConfirmPassword.Text Then
33 MessageBox.Show("Password do not match", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error)
34 NewPassword.Text = ""
35 OldPassword.Text = ""
36 ConfirmPassword.Text = ""
37 OldPassword.Focus()
38 Exit Sub
39 ElseIf OldPassword.Text = NewPassword.Text Then
40 MessageBox.Show("Password is same..Re-enter new password", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error)
41 NewPassword.Text = ""
42 ConfirmPassword.Text = ""
43 NewPassword.Focus()
44 Exit Sub
45 End If
46 con = New SqlConnection(cs)
47 con.Open()
48 Dim co As String = "update Registration set password = '" & Encrypt(NewPassword.Text) & "'where userid='" & UserID.Text & "' and password = '" & Encrypt(OldPassword.Text) & "'"
49 cmd = New SqlCommand(co)
50 cmd.Connection = con
51 RowsAffected = cmd.ExecuteNonQuery()
52 If RowsAffected > 0 Then
53 Dim st As String = "Successfully changed the password"
54 LogFunc(UserID.Text, st)
55 MessageBox.Show("Successfully changed", "Password", MessageBoxButtons.OK, MessageBoxIcon.Information)
56 Me.Hide()
57 frmLogin.Show()
58 frmLogin.UserID.Text = ""
59 frmLogin.Password.Text = ""
60 frmLogin.UserID.Focus()
61 Else
62
63 MessageBox.Show("invalid user name or password", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error)
64 UserID.Text = ""
65 NewPassword.Text = ""
66 OldPassword.Text = ""
67 ConfirmPassword.Text = ""
68 UserID.Focus()
69 End If
70 con.Close()
71 Catch ex As Exception
72 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
73 End Try
74 End Sub
75
76 Private Sub frmChangePassword1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
77 Me.Hide()
78 frmLogin.Show()
79 frmLogin.UserID.Text = ""
80 frmLogin.Password.Text = ""
81 frmLogin.UserID.Focus()
82 End Sub
83
84 Private Sub frmChangePassword_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
85
86 End Sub
87 End Class